package controllers.api;

import java.util.HashMap;
import java.util.List;
import java.util.Map;



import models.User;
import models.myThread;

public class Messages extends API {
	public static void SendMsg(){
		myThread mytread=new myThread();
		String text=request.params.get("text");
		String to=request.params.get("to");
		String uid=session.get("sessionUser");
	
		User user=User.find("by_id",uid).first();
		User userto=User.find("by_id",to).first();
		mytread.setFromId(user.getId());
		mytread.setFromName(user.getName());
		mytread.setText(text);
		mytread.setFromPrPhoto(user.getPrPhoto());
		mytread.setToId(userto.getId());
		mytread.setToName(userto.getName());
		mytread.setToPrPhoto(userto.getPrPhoto());
		mytread.save();
	}
	public static void list(){
		List<myThread> msg = myThread.find().fetch();
		json(msg);
	}
}
